import classNames from "classnames";
import "./index.scss";
import { useStore } from "../../store";

const Menu = (props) => {
  const foodsList = props.categoryList;
  const menus = foodsList.map((item) => ({ tag: item.tag, name: item.name }));
  const { changeActiveIndex, activeIndex } = useStore();
  return (
    <nav className="list-menu">
      {/* 添加active类名会变成激活状态 */}
      {menus.map((item, index) => {
        return (
          <div
            onClick={() => changeActiveIndex(index)}
            key={item.tag}
            className={classNames(
              "list-menu-item",
              activeIndex === index && "active"
            )}
          >
            {item.name}
          </div>
        );
      })}
    </nav>
  );
};

export default Menu;
